<?php
require_once("/home/bluecbhv/Jcuhelpers-WebTech/Keywords_Identifier/Execute.php");

require_once("/home/bluecbhv/Jcuhelpers-WebTech/Common/Algorithms/Content_Scraper.php");
require_once("/home/bluecbhv/Jcuhelpers-WebTech/Browshot.php");

/***********************************************
	This class would filter the search results.
************************************************/
class SearchResultsFilter extends KeywordsIdentifier {
	private $titleArray = NULL;
	private $isInteger = NULL;
	private $relevantKeywords = NULL;
	
	/************************************************************/
	
	function explodeTitle($title) {
		$this->titleArray = explode(" ", $title);
		
		foreach ($this->titleArray as $individualWord) {
			$this->isInteger = FALSE;
			
			if (is_numeric($individualWord) && $individualWord > 4 && $individualWord < 21) {
				$this->isInteger = TRUE;
				return $this->isInteger;
			}
		}
		
		return $this->isInteger;
	}
	
	/************************************************************/
	
	function getRelevantKeywords($link) {
		$this->relevantKeywords = parent::identifyKeywords($link);
		return $this->relevantKeywords;
	}
	
	/************************************************************/
	
	function getImage($link, $domain) {
		$prefix = "https://api.browshot.com/api/v1/simple?url=";
		$suffix = "&width=200&height=200&key=3L9I59n0EBWhs4k6QcM2dCTVUGYkfOl2";
		
		$domainTrimmed = rtrim($domain, ".net");
		$domainTrimmed2 = rtrim($domainTrimmed, ".com");
		$imagePath2 = "/home/bluecbhv/public_html/Jcuhelpers-WebTech/Images/".$domainTrimmed2.".jpg";
		$imagePath3 = "/Jcuhelpers-WebTech/Images/".$domainTrimmed2.".jpg";
		
		$ch = curl_init($prefix.$link.$suffix);
		
		$fp = fopen($imagePath2, 'w');
		curl_setopt($ch, CURLOPT_FILE, $fp);
		curl_setopt($ch, CURLOPT_HEADER, 0);
		
		curl_exec($ch);
		sleep(100);
		
		curl_close($ch);
		fclose($fp);

		return $imagePath3;
	}
	
	/************************************************************/
	
	function getImagePath($link, $domain) {
		$domainTrimmed = rtrim($domain, ".net");
		$domainTrimmed2 = rtrim($domainTrimmed, ".com");
		$imagePath2 = "/home/bluecbhv/public_html/Jcuhelpers-WebTech/Images/".$domainTrimmed2.".jpg";
		$imagePath3 = "/Jcuhelpers-WebTech/Images/".$domainTrimmed2.".jpg";

		return $imagePath3;
	}
}
?>